﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TMI85303.Utils;

namespace TMI85303.UI.UserControls
{
    /// <summary>
    /// Reg167Control.xaml 的交互逻辑
    /// </summary>
    public partial class Reg167Control : UserControl
    {
        public Reg167Control()
        {
            InitializeComponent();
        }
    }

    public partial class Reg167VM : ObservableObject
    {
        [ObservableProperty]
        private bool reg0 = false;

        [ObservableProperty]
        private bool reg1 = false;

        [ObservableProperty]
        private bool reg2 = false;

        [ObservableProperty]
        private bool reg3 = false;

        [ObservableProperty]
        private bool reg4 = false;

        [ObservableProperty]
        private bool reg5 = false;

        [ObservableProperty]
        private bool reg6 = false;

        [ObservableProperty]
        private bool reg7 = false;

        [ObservableProperty]
        private bool reg8 = false;

        [ObservableProperty]
        private bool reg9 = false;

        [ObservableProperty]
        private bool reg10 = false;

        [ObservableProperty]
        private bool reg11 = false;

        [ObservableProperty]
        private bool reg12 = false;

        [ObservableProperty]
        private bool reg13 = false;

        [ObservableProperty]
        private bool reg14 = false;

        [ObservableProperty]
        private bool reg15 = false;

        [RelayCommand]
        private void WriteConfig()
        {
            int writeData = 0;

            writeData |= (Reg0 ? 1 : 0) << 0;
            writeData |= (Reg1 ? 1 : 0) << 1;
            writeData |= (Reg2 ? 1 : 0) << 2;
            writeData |= (Reg3 ? 1 : 0) << 3;
            writeData |= (Reg4 ? 1 : 0) << 4;
            writeData |= (Reg5 ? 1 : 0) << 5;
            writeData |= (Reg6 ? 1 : 0) << 6;
            writeData |= (Reg7 ? 1 : 0) << 7;
            writeData |= (Reg8 ? 1 : 0) << 8;
            writeData |= (Reg9 ? 1 : 0) << 9;
            writeData |= (Reg10 ? 1 : 0) << 10;
            writeData |= (Reg11 ? 1 : 0) << 11;
            writeData |= (Reg12 ? 1 : 0) << 12;
            writeData |= (Reg13 ? 1 : 0) << 13;
            writeData |= (Reg14 ? 1 : 0) << 14;
            writeData |= (Reg15 ? 1 : 0) << 15;
            ReadWrite.WriteReg(167, writeData, 2);
        }

        [RelayCommand]
        private void ClearConfig()
        {
            ReadWrite.WriteReg(167, 0, 2);
        }

    }

}
